//var request = require('request');
var fly = require('flyio')
// var asyncs = require('async')
/* request('http://www.baidu.com',function (error,response,body) {
    if (!error && response.statusCode == 200){
        console.log(body)
    }
});

console.log("=============================");



//request("http://10.100.2.36:8086/api/operation/authenticate/account",)


fly.get('http://www.baidu.com')
    .then((response)=>{
     console.log(response)
        console.log("====================================")
     console.log(response.headers['set-cookie']);
     console.log(response.headers);
     console.log("====================================")
     console.log(response.status)
    // console.log(response.getCookies())


    })
    .catch((e)=>{
        console.log(e)
    })*/

var cookie=222 ;

var url = 'http://10.100.2.36:8086/api/operation/authenticate/account'
var repData = {
    login:"admin",
    password:"wujun27",
    type : "account"
}

var ct = {
    'content-type' : "application/json; charset=utf-8"
}

const A = new Promise( (resolve, reject) => {
    fly.request(url,repData,{
        method: 'post',
        headers: {ct},
        timeout:10000
    }).then( res => {
        console.log('A',res.data['id_token'])
        cookie = res.data['id_token']
        //加入resolve()方法后，在Promise.all().then()方法中可以对执行结果进行顺序打印
        resolve('A:'+res.data['id_token'])
    }).catch( e =>{
        reject(e)
    })
})
const B = new Promise((resolve, reject)=>{
    fly.request(url ,repData,{
        method:"post",
        headers:{ct}
    }).then(rep => {
        console.log('B',rep.data['id_token'])
        cookie =  rep.data['id_token']
        resolve('B:'+rep.data['id_token'])
    }).catch(e => {
        reject(e)
    })
})
 Promise.all([A, B]).then(data => {
     console.log('success:',data)
 })

/*asyncs.parallel({cookies : getCookie()},
    function (error,result) {
        console.log(result.cookies)
    }
    )*/



